# Copyright 2007 Eloff Enterprises
#
# Licensed under the BSD License (the "License").
# You may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#    http://rwig.googlecode.com/files/LICENSE
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
# implied.  See the License for the specific language governing
# permissions and limitations under the License.
#
# Originally developed by Daniel Eloff.

class Type(object):
    def __init__(self, conf_type, c_type, bv_char, err_val, convert_code):
        self.conf_type = conf_type
        self.c_type = c_type
        self.bv_char = bv_char
        self.err_val = err_val
        self.convert_code = convert_code

# TODO add support for the other C integer types 
# (char, uchar, short, ushort, uint, long, ulong, longlong, ulonglong)
# Also add support for unicode to wchar_t *
types_map = {
    'int' : Type('int', 'int', 'i', '-1', 'py_to_int(%s)'),
    'float' : Type('float', 'float', 'f', '0.0f', 'py_to_float(%s)'),
    'double' : Type('double', 'double', 'd', '0.0', 'py_to_double(%s)'),
    'string' : Type('string', 'char *', 's', 'NULL', 'py_to_str(%s)'),
    'bytes' : Type('bytes', 'rwig_str', 's#', 'RWIG_STR_NULL', 'py_to_rwig_str(%s)'),
    'object' : Type('object', 'PyObject *', 'O', 'NULL', '%s'),
}

def get_type(ty):
    return types_map[ty]